#include <stdlib.h>
#include "2dmass.h"
int i=0;
int j=0;
void Create( dmass* mass,int nrows, int ncoloumns, size_t size)
{
	mass->Nrows=nrows;
	mass->Ncoloumns=ncoloumns;
	mass->elem_size=size;
	mass->p=(char*)malloc((mass->Nrows)*(mass->Ncoloumns)*sizeof(size));
	for(i=0;i<mass->Nrows;i++)
	{
		
	   for(j=0;j<(mass->Ncoloumns);j++)
		{
			((mass->p))[i*(mass->Ncoloumns)+j]=1;
		}
	}
}
void del(dmass* mass)
{
	free(mass->p);
	mass->p=NULL;
	
}
int get_mass(dmass* mass,int i,int j)
{
	return mass->p[i*(mass->Ncoloumns)+j];
}
void set_mass(dmass* mass,int b,int i,int j)
{
	mass->p[i*(mass->Ncoloumns)+j]=b;
	
}
void resize_mass(dmass* mass,int New_row,int New_coloumn, size_t size)
{
	dmass* newmass;
	newmass->elem_size=size;
	newmass->Nrows=New_row;
	newmass->Ncoloumns=New_coloumn;
	newmass->p=malloc(sizeof(size));
	for(i=0;i<New_row;i++)
	{
		
		for(j=0;j<New_coloumn;j++)
		{
			newmass->p[i*(mass->Ncoloumns)+j]=0;
		}
	}
if(newmass->Ncoloumns > mass->Ncoloumns)
{
	if(newmass->Nrows > mass->Nrows)
	{

		for(i=0;i<New_row;i++)
		{
		
			for(j=0;j<New_coloumn;j++)
			{
				newmass->p[i*(newmass->Ncoloumns)+j]=mass->p[i*(mass->Ncoloumns)+j];
			}
		}
	}
}

}
void copy_mass(dmass* mass, dmass* mass1, int New_row,int New_coloumn, size_t size,int row,int coloumn)
{
	mass1->Ncoloumns=New_coloumn;
	mass1->Nrows=New_row;
	if(mass1->Ncoloumns-coloumn >mass->Ncoloumns && mass1->Nrows-row > mass->Nrows)
	{
		for(i=0;i+row<mass->Nrows;i++)
		{
			for(j=0;j+coloumn<mass->Ncoloumns;j++)
			{
				mass1->p[i*(mass1->Ncoloumns)+j]=mmass->p[(i+coloumn)*(mass->Ncoloumns)+(j+row)];
			}
		}
	}
	if(mass1->Ncoloumns-coloumn <mass->Ncoloumns || mass1->Nrows-row < mass->Nrows)
	{
		for(i=0;i<mass1->Nrows;i++)
		{
			for(j=0;j<mass1->Ncoloumns;j++)
			{
				mass1->p[i*(mass1->Ncoloumns)+j]=mass->p[(i+coloumn)*(mass->Ncoloumns)+(j+row)];
			}
		}

	}
	
			
}